﻿package gateway;

import java.net.InetSocketAddress;
import java.util.concurrent.Executors;

import model.db.DBserver;
import model.memCached.MemCachedManage;

import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;

import util.KPrintInfo;
import config.ConfigInit;
import config.ServerConfig;

public class GateWay {
	private static int port;
	public static void main(String[] arg) {
		System.out.println("-----server start------");
		config();
		
		ServerBootstrap bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
				Executors.newCachedThreadPool(), Executors.newCachedThreadPool()));
		
		bootstrap.setPipelineFactory(new MessageServerPipelineFactory());
		
		bootstrap.bind(new InetSocketAddress(port));
		
		System.out.println("Socket server bind " + port);
	}
	
	private static void config() {
		
		ConfigInit.getInstance().init();
		
		MemCachedManage.getInstance().init();
		
		String dbHost = ServerConfig.getInstance().getDbHost();
		String dbPort = ServerConfig.getInstance().getDbPort();
		String dbName = ServerConfig.getInstance().getDbName();
		String dbuserName = ServerConfig.getInstance().getDbuserName();
		String dbpsw = ServerConfig.getInstance().getDbpsw();
		

		port= ServerConfig.getInstance().getServer_port();
		
		boolean con = DBserver.getInstance().dbConnection(dbHost, dbPort, dbName, dbuserName, dbpsw);
		
		if (con) {
			KPrintInfo.println("----mysql--is ok--");
			
		} else {
			KPrintInfo.println("----mysql--is fail--");
		}
	}
	
	// end class
}
